
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_EBAS_GRUPPE_FAG_EBAS_GRUPPE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[EBAS_GRUPPE_FAG] DROP CONSTRAINT FK_EBAS_GRUPPE_FAG_EBAS_GRUPPE
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_EBAS_GRUPPE_STUDERENDE_EBAS_GRUPPE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[EBAS_GRUPPE_STUDERENDE] DROP CONSTRAINT FK_EBAS_GRUPPE_STUDERENDE_EBAS_GRUPPE
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_GRUPPE]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[EBAS_GRUPPE]
GO

CREATE TABLE [dbo].[EBAS_GRUPPE] (
	[GUID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[NAVN] [varchar] (255) COLLATE Danish_Norwegian_CI_AS NOT NULL ,
	[START_TID] [datetime] NOT NULL ,
	[SLUT_TID] [datetime] NOT NULL ,
	[STED] [varchar] (255) COLLATE Danish_Norwegian_CI_AS NULL ,
	[BEMAERKNING] [varchar] (255) COLLATE Danish_Norwegian_CI_AS NULL ,
	[EJERFORHOLD_GUID] [uniqueidentifier] NOT NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[EBAS_GRUPPE] WITH NOCHECK ADD 
	CONSTRAINT [PK_EBAS_GRUPPE] PRIMARY KEY  CLUSTERED 
	(
		[GUID]
	)  ON [PRIMARY] 
GO

 CREATE  UNIQUE  INDEX [IDX_EBAS_GRUPPE_NAVN] ON [dbo].[EBAS_GRUPPE]([NAVN]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[EBAS_GRUPPE] ADD 
	CONSTRAINT [FK_EBAS_GRUPPE_EBAS_EJERFORHOLD] FOREIGN KEY 
	(
		[EJERFORHOLD_GUID]
	) REFERENCES [dbo].[EBAS_EJERFORHOLD] (
		[GUID]
	)
GO
